package src.main.zuhe;

import java.util.ArrayList;
import java.util.List;
/**公司组织结构模拟*/
public class Composite {
    private final List<Composite> list;
    public void add(Composite c) {
        list.add(c);
    }

    final private String name;
    public Composite(String name) {
        this.list = new ArrayList<>();
        this.name = name;
    }

    //多态.递归输出list
    void printComposite() {
        System.out.println(name);
        for (Composite com : list) {
            com.printComposite();
        }
    }


    public static void main(String[] args) {
        Composite CEO = new Composite("CEO");
        Composite SubCeo1 = new Composite("SubCeo1");
        Composite SubCeo2 = new Composite("SubCeo2");
        Composite SubSubCeo1 = new Composite("SubsubCeo1");
        Composite SubSubCeo2 = new Composite("SubsubCeo2");
        Composite SubSubCeo3 = new Composite("SubsubCeo3");
        Composite SubSubCeo4 = new Composite("SubsubCeo4");
        Composite SubSubCeo5 = new Composite("SubsubCeo5");
        Composite SubSubCeo6 = new Composite("SubsubCeo6");

        SubSubCeo1.add(SubSubCeo5);
        SubSubCeo2.add(SubSubCeo6);
        SubCeo1.add(SubSubCeo1);
        SubCeo1.add(SubSubCeo2);
        SubCeo2.add(SubSubCeo3);
        SubCeo2.add(SubSubCeo4);
        CEO.add(SubCeo1);
        CEO.add(SubCeo2);
        CEO.printComposite();
    }
}
